package javacommon.tag.views;


import java.util.List;

import javacommon.tag.components.MyRadio;
import javacommon.util.PropertiesUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.components.Component;
import org.apache.struts2.components.Radio;
import org.apache.struts2.views.jsp.ui.AbstractRequiredListTag;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.util.ValueStack;
import com.tech15.core.service.SearchDataManager;

/**
 * @see Radio
 */
public class MyRadioTag extends AbstractRequiredListTag {
	private static final long serialVersionUID = 1L;
	
	protected String sql;
    protected String condition;
    protected String dataType;
    protected String isSql;
    
    private SearchDataManager searchDataManager;

	public Component getBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
		WebApplicationContext act = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
		searchDataManager = (SearchDataManager) act.getBean("searchDataManager");
    	return new MyRadio(stack, request, response);
    }
	
	@Override
    protected void populateParams(){
        super.populateParams();
        String s = PropertiesUtil.pps.getProperty(sql);
        MyRadio myRadio = (MyRadio)component;
        List<Object> list = searchDataManager.searchData(s,isSql,condition,dataType);
        myRadio.addParameter("list", list);
        myRadio.setListKey(listKey);
        myRadio.setListValue(listValue);
    }
	
	public void setCondition(String condition) {
		this.condition = condition;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public void setIsSql(String isSql) {
		this.isSql = isSql;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}
}
